<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <select name="field_name" lay-verify="required" required>
                            <option value="uid">用户ID</option>
                            <option value="account">账号</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <input name="field_value" class="layui-input" placeholder="输入搜索内容"/>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="type">
                                <option value="">类型</option>
                                <option value="1">买入</option>
                                <option value="2">卖出</option>
                                <option value="3">结息</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <select name="date_type" lay-verify="required" required>
                            <option value="created_at">创建时间</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <input type="text" autocomplete="off" id="startDate" name="start_date" class="layui-input"
                               placeholder="开始日期">
                    </div>
                    <div class="layui-inline">
                        <input type="text" autocomplete="off" id="endDate" name="end_date" class="layui-input"
                               placeholder="结束日期">
                    </div>
                    <div class="layui-inline">&emsp;
                        <button class="layui-btn icon-btn" lay-filter="search" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="test" lay-filter="test"></table>
        </div>
    </div>
</div>

<!-- js部分 -->
<script type="text/javascript" src="__TPL_RESOURCE_BACKEND__/libs/layui/layui.js"></script>
<script type="text/javascript" src="__TPL_RESOURCE_BACKEND__/js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'admin','laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laydate = layui.laydate;

        const startTime = new Date(new Date().setDate(new Date().getDate() - 30));
        startTime.setHours(0, 0, 0, 0);
        var startDate = startTime.toISOString().split('T')[0] + ' 00:00:00';

        const endTime = new Date(new Date().setDate(new Date().getDate() + 2));
        endTime.setHours(0, 0, 0, 0);
        var endDate = endTime.toISOString().split('T')[0] + ' 00:00:00';

        laydate.render({
            elem: '#startDate',
            type: 'datetime',
            value: startDate
        });

        laydate.render({
            elem: '#endDate',
            type: 'datetime',
            value: endDate
        });

        /* 渲染表格 */
        var insTb = table.render({
            elem: '#test',
            url: "{{:url('Rixibao/index')}}",
            page: {
                limit: 20
            },
            method: 'post',
            contentType: 'application/json',
            toolbar: true,
            cols: [[
                {field: 'id', title: 'ID'},
                {field: 'account', title: '账户'},
                {field: 'money', title: '金额'},
                {field: 'level_name', title: '会员等级'},
                {
                    title: '类型', templet: function (d) {
                        return [
                            '',
                            '<span style="color: #009688;">买入</span>',
                            '<span style="color: #FF5722;">卖出</span>',
                            '<span style="color: #FFB800;">结息</span>'
                        ][d.type];
                    }, align: 'center', width: 100
                },
                {field: 'created_at', title: '创建时间'}
            ]]
        });

        /* 表格搜索 */
        form.on('submit(search)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
            return false;
        });
    });
</script>
</body>
</html>
